fix: tighten Sentry idiom and typing micro-issues#96
Merged
Conversation
LOW-1: wrap_before_send_callbacks used `if not callback:` to skip None entries in *callbacks. Callables are always truthy unless they define __bool__, so the truthiness check is semantically wrong even if it happens to work. Use `if callback is None:` to match the intent. LOW-2: SentryConfig.sentry_before_send was annotated `Callable[[Any, Any], Any | None] | None`. The inner `Any | None` collapses to `Any`, so the annotation reduces to `Callable[..., Any] | None` — the union adds nothing. Use the proper `sentry_types.EventProcessor | None` instead (already imported under TYPE_CHECKING in the same file). No behavior change. Closes LOW-1 and LOW-2 from the audit.
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two micro-fixes in
sentry_instrument.py:wrap_before_send_callbacksusedif not callback:to skipNoneentries in*callbacks. Callables are always truthy unless they define__bool__, so the truthiness check is semantically wrong (happens to work for normal callables, but obscures the intent). Useif callback is None:to match the intent — also the PEP 8 canonical form for singleton checks.SentryConfig.sentry_before_sendwas annotatedCallable[[Any, Any], Any | None] | None. The innerAny | Nonecollapses toAny, so the annotation reduces toCallable[..., Any] | None— the union adds nothing. Use the propersentry_types.EventProcessor | None(string-quoted; the type lives underTYPE_CHECKING).No behavior change. No new tests — existing Sentry tests cover both paths.
Closes LOW-1 and LOW-2 from an internal audit.
Test plan
just test -- tests/instruments/test_sentry_instrument.py -v— pass.just test— 89/89.just lint— clean.🤖 Generated with Claude Code